package leetcode91_100;

import outoforder.leetcode.ListNode;

/**
 * @author shhjiang_001
 * @create 2020-07-12 13:48
 */
public class Solution92 {
    public ListNode reverseBetween(ListNode head, int m, int n) {
       if (m == 1){
           return reverseN(head,n);
       }
       head.next = reverseBetween(head.next,m-1,n-1);
       return head;
    }
    ListNode successor = null;
    private ListNode reverseN(ListNode head, int n) {
        if (n == 1){
            successor = head.next;
            return head;
        }
        ListNode last = reverseN(head.next,n-1);
        head.next.next = head;
        head.next = successor;
        return last;
    }
}
